package servlet;

import entity.PowerBattery;
import service.PowerBatteryService;
import service.impl.PowerBatteryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/PowerBatteryUpdate")
public class PowerBatteryUpdate extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("test/html;charset=utf-8");

        PowerBattery powerBattery = new PowerBattery();
        powerBattery.setId(Integer.parseInt(req.getParameter("id")));
        powerBattery.setCarName(req.getParameter("carName"));
        powerBattery.setCityName(req.getParameter("cityName"));
        powerBattery.setUserName(req.getParameter("userName"));
        powerBattery.setPressureValue(Integer.parseInt(req.getParameter("pressureValue")));
        powerBattery.setTime(req.getParameter("time"));

        PowerBatteryService powerBatteryService = new PowerBatteryServiceImpl();
        if (powerBatteryService.powerUpdate(powerBattery)>0) {
            //成功
        }else{
            //失败
        }
        resp.sendRedirect("PowerBatteryList");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
